home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2000 #5 / Amiga Plus CD - 2000 - No. 5.iso / Tools / Libs / MCC_NListtree / Developer / C / Examples / NListtree-Demo.c < prev   
Encoding:
C/C++ Source or Header  |  2000-01-01  |  27.6 KB  |  989 lines

  1. /******************************************************************************\
  2. ********************************************************************************
  3. ***
  4. ***    NListtree.mcc    Copyright (c) 1999-2000 by Apocalypse Hard- and Software
  5. ***                    Carsten Scholling
  6. ***
  7. ***    Example program for MUI class NListtree.mcc
  8. ***
  9. ***
  10. ***    Please do not use this "to be rewritten"-piece of software as an
  11. ***    information resource on how to write programs in an object oriented
  12. ***    MUI environment. It simply shows how to use some of the NListtree
  13. ***    functions.
  14. ***
  15. ***
  16. ********************************************************************************
  17. \******************************************************************************/
  18.  
  19.  
  20. /*
  21. **    Includes
  22. */
  23. #include <proto/muimaster.h>
  24.  
  25. #include <clib/alib_protos.h>
  26. #include <clib/exec_protos.h>
  27.  
  28. #include <exec/memory.h>
  29. #include <exec/types.h>
  30.  
  31. #include <string.h>
  32. #include <stdio.h>
  33.  
  34. #include "Compiler.h"
  35.  
  36. #include <libraries/mui.h>
  37.  
  38. #include <mui/nlistview_mcc.h>
  39. #include <mui/nlist_mcc.h>
  40. #include "mui/nlisttree_mcc.h"
  41.  
  42.  
  43. #ifdef MYDEBUG
  44.     #ifdef __APHASO__
  45.         #include <Debug.h>
  46.     #else
  47.         #define bug kprintf
  48.         #define D(x)
  49.         void kprintf( UBYTE *fmt, ... );
  50.     #endif
  51. #endif
  52.  
  53.  
  54. #ifndef MAKE_ID
  55. #define MAKE_ID(a,b,c,d) ((ULONG) (a)<<24 | (ULONG) (b)<<16 | (ULONG) (c)<<8 | (ULONG) (d))
  56. #endif
  57.  
  58.  
  59. /*
  60. **    Do not use stack sizes below 8KB!!
  61. */
  62. LONG __stack = 16384;
  63.  
  64.  
  65. /*
  66. **    MUI library base.
  67. */
  68. struct Library    *MUIMasterBase;
  69.  
  70. /*
  71. **    MUI objects.
  72. */
  73. STATIC APTR        app, window,lt_nodes,
  74.                 tx_info1,    tx_info2,
  75.                 sl_treecol,    st_string,
  76.                 bt_open,    bt_close,    bt_expand,    bt_collapse,
  77.                 bt_insert,    bt_remove,    bt_exchange,bt_rename,
  78.                 bt_move,    bt_copy,    bt_moveks,    bt_copyks,
  79.                 bt_find,    bt_parent,    bt_sort,    bt_getnr,
  80.                 bt_redraw,    bt_selected;
  81.  
  82.  
  83.  
  84. /*
  85. **    Sample tree structure.
  86. */
  87. struct SampleArray {
  88.     STRPTR    name;
  89.     UWORD   flags;
  90. };
  91.  
  92. STATIC const struct SampleArray sa[] =
  93. {
  94.     "comp", TNF_LIST | TNF_OPEN,
  95.         "sys", TNF_LIST | TNF_OPEN,
  96.             "amiga", TNF_LIST | TNF_OPEN,
  97.                 "misc", 0x8000,
  98.             "mac", TNF_LIST,
  99.                 "system", 0x8000,
  100.  
  101.     "de", TNF_LIST | TNF_OPEN,
  102.         "comm", TNF_LIST,
  103.             "software", TNF_LIST,
  104.                 "ums", 0x8000,
  105.         "comp", TNF_LIST | TNF_OPEN,
  106.             "sys", TNF_LIST | TNF_OPEN,
  107.                 "amiga", TNF_LIST,
  108.                     "misc", 0x8000,
  109.                     "tech", 0x8000,
  110.                 "amiga", 0x8000,
  111.  
  112.     "sort test", TNF_LIST | TNF_OPEN,
  113.         "a", 0,
  114.         "x", TNF_LIST,
  115.         "v", 0,
  116.         "g", TNF_LIST,
  117.         "h", 0,
  118.         "k", TNF_LIST,
  119.         "u", 0,
  120.         "i", TNF_LIST,
  121.         "t", 0,
  122.         "e", TNF_LIST,
  123.         "q", 0,
  124.         "s", TNF_LIST,
  125.         "c", 0,
  126.         "f", TNF_LIST,
  127.         "p", 0,
  128.         "l", TNF_LIST,
  129.         "z", 0,
  130.         "w", TNF_LIST,
  131.         "b", 0,
  132.         "o", TNF_LIST,
  133.         "d", 0,
  134.         "m", TNF_LIST,
  135.         "r", 0,
  136.         "y", TNF_LIST,
  137.         "n", 0,
  138.         "j", TNF_LIST,
  139.  
  140.  
  141.     "m", TNF_LIST,
  142.         "i", TNF_LIST,
  143.             "c", TNF_LIST,
  144.                 "h", TNF_LIST,
  145.                     "e", TNF_LIST,
  146.                         "l", TNF_LIST,
  147.                             "a", TNF_LIST,
  148.                                 "n", TNF_LIST,
  149.                                     "g", TNF_LIST,
  150.                                         "e", TNF_LIST,
  151.                                             "l", TNF_LIST,
  152.                                                 "o", 0,
  153.  
  154.     "end", TNF_LIST,
  155.         "of", TNF_LIST,
  156.             "tree", 0,
  157.  
  158.     NULL, 0
  159. };
  160.  
  161.  
  162.  
  163. /*
  164. **    Prototypes and hooks.
  165. */
  166. SAVEDS ASM LONG confunc( REG(a0) struct Hook *hook, REG(a2) Object *obj, REG(a1) struct MUIP_NListtree_ConstructMessage *msg );
  167. STATIC struct Hook conhook = { {NULL, NULL}, (void *)confunc, NULL, NULL };
  168.  
  169. SAVEDS ASM LONG desfunc( REG(a0) struct Hook *hook, REG(a2) Object *obj, REG(a1) struct MUIP_NListtree_DestructMessage *msg );
  170. STATIC struct Hook deshook = { {NULL, NULL}, (void *)desfunc, NULL, NULL };
  171.  
  172. SAVEDS ASM LONG dspfunc( REG(a0) struct Hook *hook, REG( a2 ) Object *obj, REG( a1 ) struct MUIP_NListtree_DisplayMessage *msg );
  173. STATIC struct Hook dsphook = { { NULL,NULL }, (void *)dspfunc, NULL, NULL };
  174.  
  175. SAVEDS ASM LONG insertfunc( REG(a2) APTR obj );
  176. STATIC struct Hook inserthook = { {NULL, NULL}, (void *)insertfunc, NULL, NULL };
  177.  
  178. SAVEDS ASM LONG exchangefunc( REG(a2) APTR obj, REG(a1) ULONG **para );
  179. STATIC struct Hook exchangehook = { {NULL, NULL}, (void *)exchangefunc, NULL, NULL };
  180.  
  181. SAVEDS ASM LONG renamefunc( REG(a2) APTR obj );
  182. STATIC struct Hook renamehook = { {NULL, NULL}, (void *)renamefunc, NULL, NULL };
  183.  
  184. SAVEDS ASM LONG movefunc( REG(a2) APTR obj, REG(a1) ULONG **para );
  185. STATIC struct Hook movehook = { {NULL, NULL}, (void *)movefunc, NULL, NULL };
  186.  
  187. SAVEDS ASM LONG copyfunc( REG(a2) APTR obj, REG(a1) ULONG **para );
  188. STATIC struct Hook copyhook = { {NULL, NULL}, (void *)copyfunc, NULL, NULL };
  189.  
  190. SAVEDS ASM LONG moveksfunc( REG(a2) APTR obj, REG(a1) ULONG **para );
  191. STATIC struct Hook movekshook = { {NULL, NULL}, (void *)moveksfunc, NULL, NULL };
  192.  
  193. SAVEDS ASM LONG copyksfunc( REG(a2) APTR obj, REG(a1) ULONG **para );
  194. STATIC struct Hook copykshook = { {NULL, NULL}, (void *)copyksfunc, NULL, NULL };
  195.  
  196. SAVEDS ASM LONG findnamefunc( REG(a2) APTR obj );
  197. STATIC struct Hook findnamehook = { {NULL, NULL}, (void *)findnamefunc, NULL, NULL };
  198.  
  199. SAVEDS ASM LONG getnrfunc( REG(a2) APTR obj );
  200. STATIC struct Hook getnrhook = { {NULL, NULL}, (void *)getnrfunc, NULL, NULL };
  201.  
  202. SAVEDS ASM LONG numselfunc( REG(a2) APTR obj );
  203. STATIC struct Hook numselhook = { {NULL, NULL}, (void *)numselfunc, NULL, NULL };
  204.  
  205.  
  206.  
  207. /*
  208. **    This function draws the sample tree structure.
  209. */
  210. STATIC VOID DrawSampleTree( Object *ltobj )
  211. {
  212.     struct MUI_NListtree_TreeNode *tn1, *tn2, *tn3;
  213.     WORD i = 0, j;
  214.  
  215.     tn1 = (struct MUI_NListtree_TreeNode *)DoMethod( ltobj, MUIM_NListtree_Insert, sa[i].name, (APTR)sa[i].flags, MUIV_NListtree_Insert_ListNode_Root, MUIV_NListtree_Insert_PrevNode_Tail, sa[i].flags ); i++;
  216.     tn2 = (struct MUI_NListtree_TreeNode *)DoMethod( ltobj, MUIM_NListtree_Insert, sa[i].name, (APTR)sa[i].flags, tn1, MUIV_NListtree_Insert_PrevNode_Tail, sa[i].flags ); i++;
  217.     tn1 = (struct MUI_NListtree_TreeNode *)DoMethod( ltobj, MUIM_NListtree_Insert, sa[i].name, (APTR)sa[i].flags, tn2, MUIV_NListtree_Insert_PrevNode_Tail, sa[i].flags ); i++;
  218.     tn1 = (struct MUI_NListtree_TreeNode *)DoMethod( ltobj, MUIM_NListtree_Insert, sa[i].name, (APTR)sa[i].flags, tn1, MUIV_NListtree_Insert_PrevNode_Tail, sa[i].flags ); i++;
  219.     tn1 = (struct MUI_NListtree_TreeNode *)DoMethod( ltobj, MUIM_NListtree_Insert, sa[i].name, (APTR)sa[i].flags, tn2, MUIV_NListtree_Insert_PrevNode_Tail, sa[i].flags ); i++;
  220.     tn1 = (struct MUI_NListtree_TreeNode *)DoMethod( ltobj, MUIM_NListtree_Insert, sa[i].name, (APTR)sa[i].flags, tn1, MUIV_NListtree_Insert_PrevNode_Tail, sa[i].flags ); i++;
  221.  
  222.     tn1 = (struct MUI_NListtree_TreeNode *)DoMethod( ltobj, MUIM_NListtree_Insert, sa[i].name, (APTR)sa[i].flags, MUIV_NListtree_Insert_ListNode_Root, MUIV_NListtree_Insert_PrevNode_Tail, sa[i].flags ); i++;
  223.     tn2 = (struct MUI_NListtree_TreeNode *)DoMethod( ltobj, MUIM_NListtree_Insert, sa[i].name, (APTR)sa[i].flags, tn1, MUIV_NListtree_Insert_PrevNode_Tail, sa[i].flags ); i++;
  224.     tn2 = (struct MUI_NListtree_TreeNode *)DoMethod( ltobj, MUIM_NListtree_Insert, sa[i].name, (APTR)sa[i].flags, tn2, MUIV_NListtree_Insert_PrevNode_Tail, sa[i].flags ); i++;
  225.     tn2 = (struct MUI_NListtree_TreeNode *)DoMethod( ltobj, MUIM_NListtree_Insert, sa[i].name, (APTR)sa[i].flags, tn2, MUIV_NListtree_Insert_PrevNode_Tail, sa[i].flags ); i++;
  226.     tn3 = (struct MUI_NListtree_TreeNode *)DoMethod( ltobj, MUIM_NListtree_Insert, sa[i].name, (APTR)sa[i].flags, tn1, MUIV_NListtree_Insert_PrevNode_Tail, sa[i].flags ); i++;
  227.     tn1 = (struct MUI_NListtree_TreeNode *)DoMethod( ltobj, MUIM_NListtree_Insert, sa[i].name, (APTR)sa[i].flags, tn3, MUIV_NListtree_Insert_PrevNode_Tail, sa[i].flags ); i++;
  228.     tn2 = (struct MUI_NListtree_TreeNode *)DoMethod( ltobj, MUIM_NListtree_Insert, sa[i].name, (APTR)sa[i].flags, tn1, MUIV_NListtree_Insert_PrevNode_Tail, sa[i].flags ); i++;
  229.     tn3 = (struct MUI_NListtree_TreeNode *)DoMethod( ltobj, MUIM_NListtree_Insert, sa[i].name, (APTR)sa[i].flags, tn2, MUIV_NListtree_Insert_PrevNode_Tail, sa[i].flags ); i++;
  230.     tn3 = (struct MUI_NListtree_TreeNode *)DoMethod( ltobj, MUIM_NListtree_Insert, sa[i].name, (APTR)sa[i].flags, tn2, MUIV_NListtree_Insert_PrevNode_Tail, sa[i].flags ); i++;
  231.     tn3 = (struct MUI_NListtree_TreeNode *)DoMethod( ltobj, MUIM_NListtree_Insert, sa[i].name, (APTR)sa[i].flags, tn1, MUIV_NListtree_Insert_PrevNode_Tail, sa[i].flags ); i++;
  232.  
  233.     tn1 = (struct MUI_NListtree_TreeNode *)DoMethod( ltobj, MUIM_NListtree_Insert, sa[i].name, (APTR)sa[i].flags, MUIV_NListtree_Insert_ListNode_Root, MUIV_NListtree_Insert_PrevNode_Tail, sa[i].flags ); i++;
  234.  
  235.     for( j = 0; j < 26; j++ )
  236.     {
  237.         DoMethod( ltobj, MUIM_NListtree_Insert, sa[i].name, (APTR)sa[i].flags, tn1, MUIV_NListtree_Insert_PrevNode_Tail, sa[i].flags ); i++;
  238.     }
  239.  
  240.     tn1 = (struct MUI_NListtree_TreeNode *)DoMethod( ltobj, MUIM_NListtree_Insert, sa[i].name, (APTR)sa[i].flags, MUIV_NListtree_Insert_ListNode_Root, MUIV_NListtree_Insert_PrevNode_Tail, sa[i].flags ); i++;
  241.  
  242.     for( j = 0; j < 11; j++ )
  243.     {
  244.         tn1 = (struct MUI_NListtree_TreeNode *)DoMethod( ltobj, MUIM_NListtree_Insert, sa[i].name, (APTR)sa[i].flags, tn1, MUIV_NListtree_Insert_PrevNode_Tail, sa[i].flags ); i++;
  245.     }
  246.  
  247.     tn1 = (struct MUI_NListtree_TreeNode *)DoMethod( ltobj, MUIM_NListtree_Insert, sa[i].name, (APTR)sa[i].flags, MUIV_NListtree_Insert_ListNode_Root, MUIV_NListtree_Insert_PrevNode_Tail, sa[i].flags ); i++;
  248.     tn1 = (struct MUI_NListtree_TreeNode *)DoMethod( ltobj, MUIM_NListtree_Insert, sa[i].name, (APTR)sa[i].flags, tn1, MUIV_NListtree_Insert_PrevNode_Tail, sa[i].flags ); i++;
  249.     tn1 = (struct MUI_NListtree_TreeNode *)DoMethod( ltobj, MUIM_NListtree_Insert, sa[i].name, (APTR)sa[i].flags, tn1, MUIV_NListtree_Insert_PrevNode_Tail, sa[i].flags ); i++;
  250. }
  251.  
  252.  
  253.  
  254.  
  255. /*
  256. **    Allocates memory for each entry we create.
  257. */
  258. LONG ASM SAVEDS confunc( REG(a0) struct Hook *hook, REG(a2) Object *obj, REG(a1) struct MUIP_NListtree_ConstructMessage *msg )
  259. {
  260.     struct SampleArray *sa;
  261.  
  262.     /*
  263.     **    Allocate needed piece of memory for the new entry.
  264.     */
  265.     if ( sa = (struct SampleArray *)AllocVec( sizeof( struct SampleArray) + strlen( msg->Name ) + 1, MEMF_CLEAR ) )
  266.     {
  267.         /*
  268.         **    Save the user data field right after the
  269.         **    array structure.
  270.         */
  271.         strcpy( (STRPTR)&sa[1], msg->Name );
  272.         sa->name = (STRPTR)&sa[1];
  273.  
  274.         sa->flags = (UWORD)msg->UserData;
  275.     }
  276.  
  277.     return( (LONG)sa );
  278. }
  279.  
  280.  
  281.  
  282. /*
  283. **    Free memory we just allocated above.
  284. */
  285. LONG ASM SAVEDS desfunc( REG(a0) struct Hook *hook, REG(a2) Object *obj, REG(a1) struct MUIP_NListtree_DestructMessage *msg )
  286. {
  287.     if ( msg->UserData != NULL )
  288.     {
  289.         FreeVec( msg->UserData );
  290.         msg->UserData = NULL;
  291.     }
  292.  
  293.     return( 0 );
  294. }
  295.  
  296.  
  297.  
  298. /*
  299. **    Format the entry data for displaying.
  300. */
  301. LONG ASM SAVEDS dspfunc( REG(a0) struct Hook *hook, REG( a2 ) Object *obj, REG( a1 ) struct MUIP_NListtree_DisplayMessage *msg )
  302. {
  303.     STATIC STRPTR t1 = "\033b\033uNewsgroups", t2 = "\033b\033uFlags", t3 = "subscribed", t4 = "\0", t5 = "\033b\033uCnt";
  304.     STATIC char buf[10];
  305.  
  306.     if ( msg->TreeNode != NULL )
  307.     {
  308.         /*
  309.         **    The user data is a pointer to a SampleArray struct.
  310.         */
  311.         struct SampleArray *a = (struct SampleArray *)msg->TreeNode->tn_User;
  312.  
  313.         sprintf( buf, "%3ld", msg->Array[-1] );
  314.  
  315.         *msg->Array++    = msg->TreeNode->tn_Name;
  316.         *msg->Array++    = ( a->flags & 0x8000 ) ? t3 : t4;
  317.         *msg->Array++    = buf;
  318.     }
  319.     else
  320.     {
  321.         *msg->Array++    = t1;
  322.         *msg->Array++    = t2;
  323.         *msg->Array++    = t5;
  324.     }
  325.  
  326.     return( 0 );
  327. }
  328.  
  329.  
  330.  
  331. /*
  332. **    Insert a new entry which name is given in
  333. **    the string gadget.
  334. */
  335. SAVEDS ASM LONG insertfunc( REG(a2) APTR obj )
  336. {
  337.     STRPTR x;
  338.  
  339.     /*
  340.     **    Get user string.
  341.     */
  342.     get( st_string, MUIA_String_Contents, &x );
  343.  
  344.     /*
  345.     **    Insert the new entry after
  346.     **    the active entry.
  347.     */
  348.     DoMethod( obj, MUIM_NListtree_Insert, x, 0, MUIV_NListtree_Insert_ListNode_Active,
  349.         MUIV_NListtree_Insert_PrevNode_Active, MUIV_NListtree_Insert_Flag_Active );
  350.  
  351.     return( 0 );
  352. }
  353.  
  354.  
  355.  
  356. /*
  357. **    Exchange two entries.
  358. */
  359. SAVEDS ASM LONG exchangefunc( REG(a2) APTR obj, REG(a1) ULONG **para )
  360. {
  361.     STATIC struct MUI_NListtree_TreeNode *tn1, *tn2;
  362.     STATIC LONG exchcnt = 0;
  363.     LONG x;
  364.  
  365.     if ( ( exchcnt == 0 ) && ( (ULONG)*para == 42 ) )
  366.     {
  367.         get( obj, MUIA_NListtree_Active, &tn1 );
  368.  
  369.         if ( tn1 != MUIV_NListtree_Active_Off )
  370.         {
  371.             nnset( tx_info2, MUIA_Text_Contents, "Select entry to exchange selected entry with." );
  372.  
  373.             exchcnt++;
  374.         }
  375.     }
  376.  
  377.     else if ( exchcnt == 1 )
  378.     {
  379.         get( obj, MUIA_NListtree_Active, &tn2 );
  380.  
  381.         if ( ( tn2 != MUIV_NListtree_Active_Off ) && ( tn1 != tn2 ) )
  382.         {
  383.             struct MUI_NListtree_ListNode *ln1;
  384.  
  385.             if ( ln1 = (struct MUI_NListtree_ListNode *)DoMethod( obj, MUIM_NListtree_GetEntry, tn1, MUIV_NListtree_GetEntry_Position_Parent, 0 ) )
  386.             {
  387.                 DoMethod( obj, MUIM_NListtree_Exchange, ln1, tn1, MUIV_NListtree_Exchange_ListNode2_Active, MUIV_NListtree_Exchange_TreeNode2_Active, 0 );
  388.  
  389.                 nnset( tx_info2, MUIA_Text_Contents, "Entries successfully exchanged!" );
  390.             }
  391.             else
  392.                 nnset( tx_info2, MUIA_Text_Contents, "Something went wrong! Try again to select." );
  393.         }
  394.         else
  395.             nnset( tx_info2, MUIA_Text_Contents, "You should not exchange an entry with itself!" );
  396.  
  397.         nnset( obj, MUIA_NListtree_Active, MUIV_NListtree_Active_Off );
  398.         exchcnt = 0;
  399.     }
  400.  
  401.     return( 0 );
  402. }
  403.  
  404.  
  405.  
  406. /*
  407. **    Rename the selected entry with the name is given in
  408. **    the string gadget.
  409. */
  410. SAVEDS ASM LONG renamefunc( REG(a2) APTR obj )
  411. {
  412.     struct MUI_NListtree_TreeNode *tn;
  413.     STRPTR x;
  414.  
  415.     /*
  416.     **    Get user string.
  417.     */
  418.     get( st_string, MUIA_String_Contents, &x );
  419.     get( obj, MUIA_NListtree_Active, &tn );
  420.  
  421.     /*
  422.     **    Insert the new entry sorted (compare hook)
  423.     **    into the active list node.
  424.     */
  425.     DoMethod( obj, MUIM_NListtree_Rename, tn,
  426.         x, 0 );
  427.  
  428.     return( 0 );
  429. }
  430.  
  431.  
  432.  
  433. /*
  434. **    Insert a new entry which name is given in
  435. **    the string gadget.
  436. */
  437. SAVEDS ASM LONG movefunc( REG(a2) APTR obj, REG(a1) ULONG **para )
  438. {
  439.     STATIC struct MUI_NListtree_TreeNode *tn1, *tn2;
  440.     STATIC LONG movecnt = 0;
  441.     LONG x;
  442.  
  443.     if ( ( movecnt == 0 ) && ( (ULONG)*para == 42 ) )
  444.     {
  445.         get( obj, MUIA_NListtree_Active, &tn1 );
  446.  
  447.         if ( tn1 != MUIV_NListtree_Active_Off )
  448.         {
  449.             nnset( tx_info2, MUIA_Text_Contents, "Select entry to insert after by simple click." );
  450.  
  451.             movecnt++;
  452.         }
  453.     }
  454.  
  455.     else if ( movecnt == 1 )
  456.     {
  457.         get( obj, MUIA_NListtree_Active, &tn2 );
  458.  
  459.         if ( ( tn2 != MUIV_NListtree_Active_Off ) && ( tn1 != tn2 ) )
  460.         {
  461.             struct MUI_NListtree_ListNode *ln1;
  462.  
  463.             if ( ln1 = (struct MUI_NListtree_ListNode *)DoMethod( obj, MUIM_NListtree_GetEntry, tn1, MUIV_NListtree_GetEntry_Position_Parent, 0 ) )
  464.             {
  465.                 DoMethod( obj, MUIM_NListtree_Move, ln1, tn1, MUIV_NListtree_Move_NewListNode_Active, tn2, 0 );
  466.  
  467.                 nnset( tx_info2, MUIA_Text_Contents, "Entry successfully moved!" );
  468.             }
  469.             else
  470.                 nnset( tx_info2, MUIA_Text_Contents, "Something went wrong! Try again to select destination." );
  471.         }
  472.         else
  473.             nnset( tx_info2, MUIA_Text_Contents, "You should not move an entry to itself!" );
  474.  
  475.         nnset( obj, MUIA_NListtree_Active, MUIV_NListtree_Active_Off );
  476.         movecnt = 0;
  477.     }
  478.  
  479.     return( 0 );
  480. }
  481.  
  482.  
  483. /*
  484. **    Insert a new entry which name is given in
  485. **    the string gadget.
  486. */
  487. SAVEDS ASM LONG copyfunc( REG(a2) APTR obj, REG(a1) ULONG **para )
  488. {
  489.     STATIC struct MUI_NListtree_TreeNode *tn1, *tn2;
  490.     STATIC LONG copycnt = 0;
  491.     LONG x;
  492.  
  493.     if ( ( copycnt == 0 ) && ( (ULONG)*para == 42 ) )
  494.     {
  495.         get( obj, MUIA_NListtree_Active, &tn1 );
  496.  
  497.         if ( tn1 != MUIV_NListtree_Active_Off )
  498.         {
  499.             nnset( tx_info2, MUIA_Text_Contents, "Select entry to insert after by simple click." );
  500.  
  501.             copycnt++;
  502.         }
  503.     }
  504.  
  505.     else if ( copycnt == 1 )
  506.     {
  507.         get( obj, MUIA_NListtree_Active, &tn2 );
  508.  
  509.         if ( ( tn2 != MUIV_NListtree_Active_Off ) && ( tn1 != tn2 ) )
  510.         {
  511.             struct MUI_NListtree_ListNode *ln1;
  512.  
  513.             if ( ln1 = (struct MUI_NListtree_ListNode *)DoMethod( obj, MUIM_NListtree_GetEntry, tn1, MUIV_NListtree_GetEntry_Position_Parent, 0 ) )
  514.             {
  515.                 DoMethod( obj, MUIM_NListtree_Copy, ln1, tn1, MUIV_NListtree_Copy_DestListNode_Active, tn2, 0 );
  516.  
  517.                 nnset( tx_info2, MUIA_Text_Contents, "Entry successfully copied!" );
  518.             }
  519.             else
  520.                 nnset( tx_info2, MUIA_Text_Contents, "Something went wrong! Try again to select destination." );
  521.         }
  522.         else
  523.             nnset( tx_info2, MUIA_Text_Contents, "You should not copy an entry to itself!" );
  524.  
  525.         nnset( obj, MUIA_NListtree_Active, MUIV_NListtree_Active_Off );
  526.         copycnt = 0;
  527.     }
  528.  
  529.     return( 0 );
  530. }
  531.  
  532.  
  533.  
  534. /*
  535. **    Move KeepStructure
  536. */
  537. SAVEDS ASM LONG moveksfunc( REG(a2) APTR obj, REG(a1) ULONG **para )
  538. {
  539.     STATIC struct MUI_NListtree_TreeNode *tn1, *tn2;
  540.     STATIC LONG movekscnt = 0;
  541.     LONG x;
  542.  
  543.     if ( ( movekscnt == 0 ) && ( (ULONG)*para == 42 ) )
  544.     {
  545.         get( obj, MUIA_NListtree_Active, &tn1 );
  546.  
  547.         if ( tn1 != MUIV_NListtree_Active_Off )
  548.         {
  549.             nnset( tx_info2, MUIA_Text_Contents, "Select entry to make KeepStructure move with." );
  550.  
  551.             movekscnt++;
  552.         }
  553.     }
  554.  
  555.     else if ( movekscnt == 1 )
  556.     {
  557.         get( obj, MUIA_NListtree_Active, &tn2 );
  558.  
  559.         if ( ( tn2 != MUIV_NListtree_Active_Off ) && ( tn1 != tn2 ) )
  560.         {
  561.             struct MUI_NListtree_ListNode *ln1;
  562.  
  563.             if ( ln1 = (struct MUI_NListtree_ListNode *)DoMethod( obj, MUIM_NListtree_GetEntry, tn1, MUIV_NListtree_GetEntry_Position_Parent, 0 ) )
  564.             {
  565.                 DoMethod( obj, MUIM_NListtree_Move, ln1, tn1, MUIV_NListtree_Move_NewListNode_Active, tn2, MUIV_NListtree_Move_Flag_KeepStructure );
  566.  
  567.                 nnset( tx_info2, MUIA_Text_Contents, "Entry successfully moved (structure keeped)" );
  568.             }
  569.             else
  570.                 nnset( tx_info2, MUIA_Text_Contents, "Something went wrong! Try again to select destination." );
  571.         }
  572.         else
  573.             nnset( tx_info2, MUIA_Text_Contents, "You should not move an entry to itself!" );
  574.  
  575.         nnset( obj, MUIA_NListtree_Active, MUIV_NListtree_Active_Off );
  576.         movekscnt = 0;
  577.     }
  578.  
  579.     return( 0 );
  580. }
  581.  
  582.  
  583. /*
  584. **    Copy KeepStructure
  585. */
  586. SAVEDS ASM LONG copyksfunc( REG(a2) APTR obj, REG(a1) ULONG **para )
  587. {
  588.     STATIC struct MUI_NListtree_TreeNode *tn1, *tn2;
  589.     STATIC LONG copykscnt = 0;
  590.     LONG x;
  591.  
  592.     if ( ( copykscnt == 0 ) && ( (ULONG)*para == 42 ) )
  593.     {
  594.         get( obj, MUIA_NListtree_Active, &tn1 );
  595.  
  596.         if ( tn1 != MUIV_NListtree_Active_Off )
  597.         {
  598.             nnset( tx_info2, MUIA_Text_Contents, "Select entry to make KeepStructure copy with." );
  599.  
  600.             copykscnt++;
  601.         }
  602.     }
  603.  
  604.     else if ( copykscnt == 1 )
  605.     {
  606.         get( obj, MUIA_NListtree_Active, &tn2 );
  607.  
  608.         if ( ( tn2 != MUIV_NListtree_Active_Off ) && ( tn1 != tn2 ) )
  609.         {
  610.             struct MUI_NListtree_ListNode *ln1;
  611.  
  612.             if ( ln1 = (struct MUI_NListtree_ListNode *)DoMethod( obj, MUIM_NListtree_GetEntry, tn1, MUIV_NListtree_GetEntry_Position_Parent, 0 ) )
  613.             {
  614.                 DoMethod( obj, MUIM_NListtree_Copy, ln1, tn1, MUIV_NListtree_Copy_DestListNode_Active, tn2, MUIV_NListtree_Copy_Flag_KeepStructure );
  615.  
  616.                 nnset( tx_info2, MUIA_Text_Contents, "Entry successfully copied (structure keeped)" );
  617.             }
  618.             else
  619.                 nnset( tx_info2, MUIA_Text_Contents, "Something went wrong! Try again to select destination." );
  620.         }
  621.         else
  622.             nnset( tx_info2, MUIA_Text_Contents, "You should not copy an entry to itself!" );
  623.  
  624.         nnset( obj, MUIA_NListtree_Active, MUIV_NListtree_Active_Off );
  625.         copykscnt = 0;
  626.     }
  627.  
  628.     return( 0 );
  629. }
  630.  
  631.  
  632.  
  633. /*
  634. **    Find the specified tree node by name.
  635. */
  636. SAVEDS ASM LONG findnamefunc( REG(a2) APTR obj )
  637. {
  638.     struct MUI_NListtree_TreeNode *tn;
  639.     char buf[100];
  640.     STRPTR x;
  641.  
  642.     /*
  643.     **    Let us see, which string the user wants to search for...
  644.     */
  645.     get( st_string, MUIA_String_Contents, &x );
  646.  
  647.     /*
  648.     **    Is it somewhere in the tree?
  649.     */
  650.     if ( tn = (struct MUI_NListtree_TreeNode *)DoMethod(obj, MUIM_NListtree_FindName, MUIV_NListtree_FindName_ListNode_Root, x, 0 ) )
  651.     {
  652.         /*
  653.         **    If so, activate it (activation is only done
  654.         **    if entry is visible).
  655.         */
  656.         set( obj, MUIA_NListtree_Active, tn );
  657.     }
  658.     else
  659.     {
  660.         /*
  661.         **    Not found. Inform the user.
  662.         */
  663.         nnset( tx_info1, MUIA_Text_Contents, "NOT found specified node!" );
  664.         nnset( tx_info2, MUIA_Text_Contents, "" );
  665.     }
  666.  
  667.     return( 0 );
  668. }
  669.  
  670.  
  671.  
  672. /*
  673. **    Find the specified tree node by name.
  674. */
  675. SAVEDS ASM LONG getnrfunc( REG(a2) APTR obj )
  676. {
  677.     LONG temp;
  678.  
  679.     temp = DoMethod( obj, MUIM_NListtree_GetNr,
  680.         MUIV_NListtree_GetNr_TreeNode_Active, MUIV_NListtree_GetNr_Flag_CountLevel );
  681.  
  682.     if ( temp == 1 )
  683.         DoMethod( tx_info1, MUIM_SetAsString, MUIA_Text_Contents, "1 entry in parent node." );
  684.     else
  685.         DoMethod( tx_info1, MUIM_SetAsString, MUIA_Text_Contents, "%ld entries in parent node.", temp );
  686.  
  687.     return( 0 );
  688. }
  689.  
  690.  
  691. /*
  692. **    Find the specified tree node by name.
  693. */
  694. SAVEDS ASM LONG numselfunc( REG(a2) APTR obj )
  695. {
  696.     LONG temp = 0;
  697.  
  698.     DoMethod( obj, MUIM_NListtree_Select, MUIV_NListtree_Select_All,
  699.         MUIV_NListtree_Select_Ask, 0, &temp );
  700.  
  701.     if ( temp == 1 )
  702.         DoMethod( tx_info1, MUIM_SetAsString, MUIA_Text_Contents, "1 node selected." );
  703.     else
  704.         DoMethod( tx_info1, MUIM_SetAsString, MUIA_Text_Contents, "%ld nodes selected.", temp );
  705.  
  706.     return( 0 );
  707. }
  708.  
  709.  
  710.  
  711.  
  712.  
  713. /*
  714. **    Main
  715. */
  716. int main( int argc, STRPTR argv[] )
  717. {
  718.     ULONG signals;
  719.  
  720.  
  721.     /*
  722.     **    Is MUI V19 available?
  723.     */
  724.     if ( MUIMasterBase = OpenLibrary( "muimaster.library", 19 ) )
  725.     {
  726.         /*
  727.         **    Create application object.
  728.         */
  729.         app = ApplicationObject,
  730.             MUIA_Application_Title,            "NListtree-Demo",
  731.             MUIA_Application_Copyright,        "©1999-2000 by Apocalypse Hard- and Software",
  732.             MUIA_Application_Author,        "Carsten Scholling",
  733.             MUIA_Application_Description,    "Demonstration program for MUI class NListtree.mcc",
  734.             MUIA_Application_Base,            "NLISTTREEDEMO",
  735.  
  736.             /*
  737.             **    Build the window.
  738.             */
  739.             SubWindow, window = WindowObject,
  740.                 MUIA_Window_Title,            "NListtree-Demo",
  741.                 MUIA_Window_ID,                MAKE_ID( 'N', 'L', 'T', 'R' ),
  742.                 MUIA_Window_AppWindow,        TRUE,
  743.                 WindowContents,                VGroup,
  744.  
  745.                     /*
  746.                     **    Create a NListview embedded NListtree object
  747.                     */
  748.                     Child, NListviewObject,
  749.                         MUIA_ShortHelp,            "The NListtree object...",
  750.                         MUIA_NListview_NList,    lt_nodes = NListtreeObject,
  751.                             InputListFrame,
  752.                             MUIA_CycleChain,                TRUE,
  753.                             MUIA_NListtree_MultiSelect,        MUIV_NListtree_MultiSelect_Shifted,
  754.                             MUIA_NListtree_DisplayHook,        &dsphook,
  755.                             MUIA_NListtree_ConstructHook,    &conhook,
  756.                             MUIA_NListtree_DestructHook,    &deshook,
  757.                             MUIA_NListtree_CompareHook,        MUIV_NListtree_CompareHook_LeavesMixed,
  758.                             MUIA_NListtree_DoubleClick,        MUIV_NListtree_DoubleClick_Tree,
  759.                             MUIA_NListtree_EmptyNodes,        FALSE,
  760.                             MUIA_NListtree_TreeColumn,        0,
  761.                             MUIA_NListtree_DragDropSort,    TRUE,
  762.                             MUIA_NListtree_Title,            TRUE,
  763.                             MUIA_NListtree_Format,            ",,",
  764.                         End,
  765.                     End,
  766.  
  767.                     /*
  768.                     **    Build some controls.
  769.                     */
  770.                     Child, tx_info1 = TextObject,
  771.                         MUIA_Background, MUII_TextBack,
  772.                         TextFrame,
  773.                     End,
  774.  
  775.                     Child, tx_info2 = TextObject,
  776.                         MUIA_Background, MUII_TextBack,
  777.                         TextFrame,
  778.                     End,
  779.  
  780.                     Child, ColGroup( 2 ),
  781.                         Child, FreeKeyLabel( "TreeCol:", 'c' ),
  782.                         Child, sl_treecol    = Slider( 0, 2, 0 ),
  783.                     End,
  784.  
  785.                     Child, HGroup,
  786.                         Child, st_string = StringObject,
  787.                             StringFrame,
  788.                             MUIA_String_MaxLen, 50,
  789.                         End,
  790.                     End,
  791.  
  792.  
  793.                     Child, ColGroup( 4 ),
  794.                         Child, bt_open        = KeyButton( "Open",        'o' ),
  795.                         Child, bt_close        = KeyButton( "Close",        'c' ),
  796.                         Child, bt_expand    = KeyButton( "Expand",        'e' ),
  797.                         Child, bt_collapse    = KeyButton( "Collapse",    'a' ),
  798.  
  799.                         Child, bt_insert    = KeyButton( "Insert",        'i' ),
  800.                         Child, bt_remove    = KeyButton( "Remove",        'r' ),
  801.                         Child, bt_exchange    = KeyButton( "Exchange",    'x' ),
  802.                         Child, bt_rename    = KeyButton( "Rename",        'r' ),
  803.  
  804.                         Child, bt_move        = KeyButton( "Move",        'm' ),
  805.                         Child, bt_copy        = KeyButton( "Copy",        'y' ),
  806.                         Child, bt_moveks    = KeyButton( "Move KS",        'v' ),
  807.                         Child, bt_copyks    = KeyButton( "Copy KS",        'k' ),
  808.  
  809.                         Child, bt_find        = KeyButton( "FindName",    'f' ),
  810.                         Child, bt_parent    = KeyButton( "Parent",        'p' ),
  811.                         Child, bt_sort        = KeyButton( "Sort",        's' ),
  812.                         Child, bt_getnr        = KeyButton( "GetNr",        'n' ),
  813.  
  814.                         Child, bt_redraw    = KeyButton( "Redraw",        'w' ),
  815.                         Child, bt_selected    = KeyButton( "Selected",    'd' ),
  816.                         Child, HVSpace,
  817.                         Child, HVSpace,
  818.                     End,
  819.  
  820.                 End,
  821.  
  822.             End,
  823.         End;
  824.  
  825.  
  826.         if( app )
  827.         {
  828.             /*
  829.             **    generate notifications
  830.             */
  831.             DoMethod( window, MUIM_Notify, MUIA_Window_CloseRequest, TRUE,
  832.                 app, 2, MUIM_Application_ReturnID, MUIV_Application_ReturnID_Quit);
  833.  
  834.             /*
  835.             **    open/close/expand/collapse
  836.             */
  837.             DoMethod( bt_open, MUIM_Notify, MUIA_Pressed, FALSE,
  838.                 lt_nodes, 4, MUIM_NListtree_Open, MUIV_NListtree_Open_ListNode_Active, MUIV_NListtree_Open_TreeNode_Active, 0 );
  839.  
  840.             DoMethod( bt_close, MUIM_Notify, MUIA_Pressed, FALSE,
  841.                 lt_nodes, 4, MUIM_NListtree_Close, MUIV_NListtree_Close_ListNode_Active, MUIV_NListtree_Close_TreeNode_Active, 0 );
  842.  
  843.             DoMethod( bt_expand, MUIM_Notify, MUIA_Pressed, FALSE,
  844.                 lt_nodes, 4, MUIM_NListtree_Open, MUIV_NListtree_Open_ListNode_Root, MUIV_NListtree_Open_TreeNode_All, 0 );
  845.  
  846.             DoMethod( bt_collapse, MUIM_Notify, MUIA_Pressed, FALSE,
  847.                 lt_nodes, 4, MUIM_NListtree_Close, MUIV_NListtree_Close_ListNode_Root, MUIV_NListtree_Close_TreeNode_All, 0 );
  848.  
  849.  
  850.  
  851.             /*
  852.             **    insert/remove/exchange/rename
  853.             */
  854.             DoMethod( bt_insert, MUIM_Notify, MUIA_Pressed, FALSE,
  855.                 lt_nodes, 2, MUIM_CallHook, &inserthook );
  856.  
  857.             DoMethod( bt_remove, MUIM_Notify, MUIA_Pressed, FALSE,
  858.                 lt_nodes, 4, MUIM_NListtree_Remove, MUIV_NListtree_Remove_ListNode_Active, MUIV_NListtree_Remove_TreeNode_Active, 0 );
  859.  
  860.             DoMethod( bt_exchange, MUIM_Notify, MUIA_Pressed, FALSE,
  861.                 lt_nodes, 3, MUIM_CallHook, &exchangehook, 42 );
  862.  
  863.             DoMethod( lt_nodes, MUIM_Notify, MUIA_NListtree_Active, MUIV_EveryTime,
  864.                 lt_nodes, 3, MUIM_CallHook, &exchangehook, 0 );
  865.  
  866.             DoMethod( bt_rename, MUIM_Notify, MUIA_Pressed, FALSE,
  867.                 lt_nodes, 2, MUIM_CallHook, &renamehook );
  868.  
  869.  
  870.             /*
  871.             **    move/copy/moveks/copyks
  872.             */
  873.             DoMethod( bt_move, MUIM_Notify, MUIA_Pressed, FALSE,
  874.                 lt_nodes, 3, MUIM_CallHook, &movehook, 42 );
  875.  
  876.             DoMethod( lt_nodes, MUIM_Notify, MUIA_NListtree_Active, MUIV_EveryTime,
  877.                 lt_nodes, 3, MUIM_CallHook, &movehook, 0 );
  878.  
  879.             DoMethod( bt_copy, MUIM_Notify, MUIA_Pressed, FALSE,
  880.                 lt_nodes, 3, MUIM_CallHook, ©hook, 42 );
  881.  
  882.             DoMethod( lt_nodes, MUIM_Notify, MUIA_NListtree_Active, MUIV_EveryTime,
  883.                 lt_nodes, 3, MUIM_CallHook, ©hook, 0 );
  884.  
  885.             DoMethod( bt_moveks, MUIM_Notify, MUIA_Pressed, FALSE,
  886.                 lt_nodes, 3, MUIM_CallHook, &movekshook, 42 );
  887.  
  888.             DoMethod( lt_nodes, MUIM_Notify, MUIA_NListtree_Active, MUIV_EveryTime,
  889.                 lt_nodes, 3, MUIM_CallHook, &movekshook, 0 );
  890.  
  891.             DoMethod( bt_copyks, MUIM_Notify, MUIA_Pressed, FALSE,
  892.                 lt_nodes, 3, MUIM_CallHook, ©kshook, 42 );
  893.  
  894.             DoMethod( lt_nodes, MUIM_Notify, MUIA_NListtree_Active, MUIV_EveryTime,
  895.                 lt_nodes, 3, MUIM_CallHook, ©kshook, 0 );
  896.  
  897.  
  898.             /*
  899.             **    find/parent/sort/getnr
  900.             */
  901.             DoMethod( bt_find, MUIM_Notify, MUIA_Pressed, FALSE,
  902.                 lt_nodes, 2, MUIM_CallHook, &findnamehook );
  903.  
  904.             DoMethod( bt_parent, MUIM_Notify, MUIA_Pressed, FALSE,
  905.                 lt_nodes, 3, MUIM_Set, MUIA_NListtree_Active, MUIV_NListtree_Active_Parent );
  906.  
  907.             DoMethod( bt_sort, MUIM_Notify, MUIA_Pressed, FALSE,
  908.                 lt_nodes, 3, MUIM_NListtree_Sort, MUIV_NListtree_Sort_TreeNode_Active, 0 );
  909.  
  910.             DoMethod( bt_getnr, MUIM_Notify, MUIA_Pressed, FALSE,
  911.                 lt_nodes, 2, MUIM_CallHook, &getnrhook );
  912.  
  913.  
  914.             /*
  915.             **    redraw/selected
  916.             */
  917.             DoMethod( bt_redraw, MUIM_Notify, MUIA_Pressed, FALSE,
  918.                 lt_nodes, 3, MUIM_NListtree_Redraw, MUIV_NListtree_Redraw_All );
  919.  
  920.             DoMethod( bt_selected, MUIM_Notify, MUIA_Pressed, FALSE,
  921.                 lt_nodes, 2, MUIM_CallHook, &numselhook );
  922.  
  923.  
  924.             /*
  925.             **    misc
  926.             */
  927.             DoMethod( sl_treecol, MUIM_Notify, MUIA_Slider_Level, MUIV_EveryTime,
  928.                 lt_nodes, 3, MUIM_Set, MUIA_NListtree_TreeColumn, MUIV_TriggerValue );
  929.  
  930.             DoMethod( lt_nodes, MUIM_Notify, MUIA_NListtree_Active, MUIV_EveryTime,
  931.                 tx_info1, 4, MUIM_SetAsString, MUIA_Text_Contents, "Active node: 0x%08lx", MUIV_TriggerValue );
  932.  
  933.             DoMethod( lt_nodes, MUIM_Notify, MUIA_NListtree_ActiveList, MUIV_EveryTime,
  934.                 tx_info2, 4, MUIM_SetAsString, MUIA_Text_Contents, "Active list: 0x%08lx", MUIV_TriggerValue );
  935.  
  936.             DoMethod( lt_nodes, MUIM_Notify, MUIA_NListtree_DoubleClick, MUIV_EveryTime,
  937.                 tx_info1, 4, MUIM_SetAsString, MUIA_Text_Contents, "Double clicked on node: 0x%08lx", MUIV_TriggerValue );
  938.  
  939.  
  940.             /*
  941.             **    Insert sample nodes
  942.             */
  943.             DrawSampleTree( lt_nodes );
  944.  
  945.  
  946.             /*
  947.             **    Open the window
  948.             **
  949.             */
  950.             set( window, MUIA_Window_Open, TRUE );
  951.  
  952.  
  953.             /*
  954.             **    Minimal input loop.
  955.             */
  956.             while( DoMethod( app, MUIM_Application_NewInput, &signals ) != MUIV_Application_ReturnID_Quit )
  957.             {
  958.                 if ( signals )
  959.                 {
  960.                     signals = Wait( signals | SIGBREAKF_CTRL_C );
  961.  
  962.                     if ( signals & SIGBREAKF_CTRL_C )
  963.                         break;
  964.                 }
  965.             }
  966.  
  967.             /*
  968.             **    Close the window.
  969.             */
  970.             set( window, MUIA_Window_Open, FALSE );
  971.  
  972.  
  973.             /*
  974.             **    Shutdown
  975.             */
  976.             MUI_DisposeObject( app );
  977.         }
  978.         else
  979.             printf( "Failed to create Application.\n" );
  980.  
  981.  
  982.         CloseLibrary( MUIMasterBase );
  983.     }
  984.  
  985.     return( 0 );
  986. }
  987.  
  988.  
  989.